<?php
namespace App\WsController;

use App\Logic\Friend\FriendLogic;
use App\Msg\MsgCode;
use App\Utility\Validator;
use EasySwoole\Core\Http\Message\Status;

class Friend extends WsAbstract
{

    function addFriend()
    {
        $request = $this->request()->getArg("content");
        $friendUid = trim($request['FriendUid']);
        $this->checkViewForm(Validator::isEmpty($friendUid), MsgCode::FRIENDUID_IS_NYLL, "", "friend");
        (new FriendLogic())->addFriend($this->userinfo, $friendUid);
        $this->writeJson(Status::CODE_OK, [], "添加" . $friendUid . "为好友的申请发送成功");
    }

    function PushMessageToFriend()
    {
        $request = $this->request()->getArg("content");
        
        $fuid = $request['FriendUid'];
        
        $this->checkViewForm(Validator::isEmpty($fuid), MsgCode::FRIENDUID_IS_NYLL, "", "friend");
        
        $message = $request['message'];
        $this->checkViewForm(Validator::isEmpty($message), MsgCode::SEND_MSG_NULL, "", "message");
        
        (new FriendLogic())->PushMessageToFriend($this->userinfo, $message, $fuid);
        $this->writeJson(MsgCode::MESSAGE_TO_FRIEND_SUCCESS, [], "给好友" . $fuid . "的消息发送成功");
    }
}